#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <time.h>

#define NUM_DICE 6

int roll_dice(void);
bool play_game(void);

int main()
{
    int win_time = 0, loss_time = 0;
    char command;
    do
    {
        if (play_game()){
            win_time++;
            printf("You win!\n");
        } else {
            loss_time++;
            printf("You lose!\n");
        }
        printf("Play again? (Y/N) ");
        scanf(" %c", &command);
        printf("\n");
    } while (command == 'Y' || command == 'y');

    printf("Wins: %d   Losses: %d", win_time, loss_time);
    return 0;
}

int roll_dice(void)
{
    return rand() % NUM_DICE + rand() % NUM_DICE + 2;
}

bool play_game(void)
{
    int dice_value = roll_dice(), point;
    printf("You rolled: %d\n", dice_value);

    switch (dice_value) {
        case 2: case 3: case 12: 
                return false;
        case 7: case 11:
                return true;
        default:
                point = dice_value;
                printf("Your point is %d\n", point);
                while (true) {
                    dice_value = roll_dice();
                    printf("You rolled: %d\n", dice_value);
                    if (dice_value == point)
                        return true;
                    if (dice_value == 11)
                        return false;
                }
    }
}
